package com.sugar.subscribe.course.module.business.controller.app.coachwallet;

import com.sugar.subscribe.course.framework.common.pojo.CommonResult;
import com.sugar.subscribe.course.framework.common.pojo.PageResult;
import com.sugar.subscribe.course.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.subscribe.course.module.business.controller.app.coachwallet.vo.AppCoachProfitHistoryReqVO;
import com.sugar.subscribe.course.module.business.controller.app.coachwallet.vo.AppCoachProfitHistoryRespVO;
import com.sugar.subscribe.course.module.business.controller.app.coachwallet.vo.AppCoachProfitRespVO;
import com.sugar.subscribe.course.module.business.controller.app.coachwallet.vo.AppCoachWalletRespVO;
import com.sugar.subscribe.course.module.business.service.coachwallet.CoachWalletService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.sugar.subscribe.course.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 教练钱包")
@RestController
@RequestMapping("/biz/coach-wallet")
@Validated
public class AppCoachWalletController {

    @Resource
    private CoachWalletService coachWalletService;

    @GetMapping("/get")
    @Operation(summary = "获得教练钱包")
    public CommonResult<AppCoachWalletRespVO> getCoachWallet() {
        return success(coachWalletService.appGetCoachWallet(SecurityFrameworkUtils.getLoginUserId(true)));
    }

    @GetMapping("/profit")
    @Operation(summary = "获得教练收益统计")
    @Parameter(name = "type", description = "类型（0今日；1昨日；2本月；3上月）", required = true, example = "1024")
    public CommonResult<AppCoachProfitRespVO> getCoachProfit(@RequestParam("type") Integer type) {
        return success(coachWalletService.getCoachProfit(SecurityFrameworkUtils.getLoginUserId(true), type));
    }

    @GetMapping("/profit/history")
    @Operation(summary = "获得教练收益历史数据（pageSize 传 5 吧）")
    public CommonResult<PageResult<AppCoachProfitHistoryRespVO>> getCoachProfitHistoryPage(@Valid AppCoachProfitHistoryReqVO reqVO) {
        return success(coachWalletService.getCoachProfitHistoryPage(SecurityFrameworkUtils.getLoginUserId(true), reqVO));
    }
}